package com.baizhi.springmvc.service.imp;


import com.baizhi.springmvc.dao.BookDao;
import com.baizhi.springmvc.entity.Book;
import com.baizhi.springmvc.service.BookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class BookServiceImp implements BookService {
    @Autowired
    private  BookDao bookDao;
    @Override
    public List<Book> selectByInventory() {
        List<Book> bookList = bookDao.selectByInventory();
        return bookList;
    }

    @Override
    public List<Book> selectBySalenum() {
        List<Book> bookList = bookDao.selectBySalenum();
        return bookList;
    }

    @Override
    public List<Book> selectByGroundingDate() {
        List<Book> bookList = bookDao.selectByGroundingDate();
        return bookList;
    }

    @Override
    public List<Book> selectByCustome_score() {
        List<Book> bookList = bookDao.selectByCustome_score();
        return bookList;
    }

    @Override
    public List<Book> selectByFirstid(Integer firstid,Integer pageNum,Integer pageSize) {
        Integer start=(pageNum-1)*pageSize;
        List<Book> bookList = bookDao.selectByFirstid(firstid,start,pageSize);
        return bookList;
    }

    @Override
    public List<Book> selectByTwoid(Integer twoid,Integer pageNum,Integer pageSize) {
        Integer start=(pageNum-1)*pageSize;
        List<Book> bookList = bookDao.selectByTwoid(twoid,start,pageSize);
        return bookList;
    }

    @Override
    public Integer firstTotalPage(Integer cid, Integer pageSize) {
        Integer count = bookDao.firstCount(cid);
        Integer firstTotalPage=count%pageSize==0?count/pageSize:count/pageSize+1;
        return firstTotalPage;
    }

    @Override
    public Integer twoTotalPage(Integer cid, Integer pageSize) {
        Integer count = bookDao.twoCount(cid);
        Integer twoTotalPage=count%pageSize==0?count/pageSize:count/pageSize+1;
        return twoTotalPage;
    }

    @Override
    public Book selectOne(Integer id) {
        Book book = bookDao.selectOne(id);
        return book;
    }
}
